//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#pragma once

#include "Scene2D/Render/RenderObject.h"

namespace Engine
{
namespace Scene2D
{

	//
	// Render Queue
	//

	struct RenderQueue
	{
	// types
	public:
		typedef array< RenderObject >									render_objects_t;
		typedef static_array< render_objects_t, ERenderLayer::_COUNT >	render_layers_t;


	// variables
	private:
		render_layers_t		_layers;

		rect				_frustumRect;


	// methods
	public:
		RenderQueue ()
		{}


		void Setup (const rect &frustum)
		{
			Clear();

			_frustumRect	= frustum;
		}


		void Clear ()
		{
			FOR( i, _layers ) {
				_layers[i].ClearMem();
			}
		}


		bool IsVisible (const rect &aabb) const
		{
			return _frustumRect.IntersectRect( aabb );
		}


		void Push (const RenderObject &ro, ERenderLayer::type layer)
		{
			_layers[ layer ].PushBack( ro );
		}


		void Draw (ERenderLayer::type layer) const
		{
			render_objects_t const &	layers = GetLayers( layer );

			FOR( i, layers ) {
				layers[i].Draw();
			}
		}

		render_objects_t const &	GetLayers (ERenderLayer::type layer) const	{ return _layers[ layer ]; }
	};


}	// Scene2D
}	// Engine